import express from 'express';
const router = express.Router();

router.get('/:module/:component', function(req, res, next) {
	const module = req.params.module;
	const component = req.params.component;
	console.log("access-two:",module,"|",component)
	import("../modules/"+[module,component,"route"].join("/")).then((loadDYRouter) => {
	    loadDYRouter(req,res,next)
	}).catch(err=>{
		console.log(err,"------")
		next();
	});
});
router.get('/:component', function(req, res, next) {
	const component = req.params.component;
	console.log("access-one:",component)
	import("../modules/"+[component,"route"].join("/")).then((loadDYRouter) => {
	    loadDYRouter(req,res,next)
	}).catch(err=>{
		console.log(err,"------")
		next();
	});
});


// Promise.all([
//     import('./a.js'),
//     import('./b.js'),
//     import('./c.js'),
// ])
// .then(([a, {default: b}, {c}]) => {
//     console.log('a.js is loaded dynamically');

//     b('isDynamic');

//     c('isDynamic');
// });

module.exports = router;